package com.CNMedical.common.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.CNMedical.common.utils.SecurityUtils;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * mybatis-plus 自动注入
 *
 * @author Rainbow
 * @date 2021/11/22 14:40
 */
@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "delFlag", String.class, "0");
        this.strictInsertFill(metaObject, "createDate", Date::new, Date.class);
        this.strictInsertFill(metaObject, "createId", String.class, SecurityUtils.getUserId().toString());
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictUpdateFill(metaObject, "updateDate", Date::new, Date.class);
        this.strictInsertFill(metaObject, "updateId", String.class, SecurityUtils.getUserId().toString());
    }
}
